﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;

namespace CompilerLib.Scanner
{
    public abstract class RegularExpression
    {
        public static RegularExpression Symbol(char symbol)
        {
            return new SymbolExpression(symbol);
        }
        /// <summary>
        /// *
        /// </summary>
        /// <returns></returns>
        public RegularExpression Many()
        {
            if (this is KleeneStarExpression)
            {
                return this;
            }
            else
            {
                return new KleeneStarExpression(this);
            }
        }
        /// <summary>
        /// +
        /// </summary>
        /// <returns></returns>
        public RegularExpression Many1()
        {//输出有bug  (a|b)+  输出是 a|b(a|b)*
            return new ConcatenationExpression(this, new KleeneStarExpression(this));
        }
        public static RegularExpression operator |(RegularExpression exp1, RegularExpression exp2)
        {
            return new AlternationExpression(exp1, exp2);
        }
        [SpecialName]
        public static RegularExpression operator &(RegularExpression left, RegularExpression right)
        {
            return new ConcatenationExpression(left, right);
        }
        internal abstract T Accept<T>(RegularExpressionConverter<T> converter);
    }
}
